home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Shareware World
/
Info
/
For Developers
/
Mops 3.4.sea
/
Quick Edit ƒ
/
Subject Glossary
/
Arithmetic
next >
Wrap
Text File
|
1992-12-11
|
3KB
|
128 lines
NUMERIC BASE
BASE -- n
This value contains the current number base used for the input and output
conversions.
DECIMAL -- Sets base to 10.
HEX -- Sets base to 16.
$ -- n : lit The literal will be interpretted as a base 16 number
DIGIT c base -- n2 t | f
Converts the ASCII character c using base into its binary equivalent n2,
and leaves a true flag; if conversion fails, leaves a false flag only.
Digit is a primitive used by (number).
COMPILATION ONLY
1+ n -- n+1
1- n -- n-1
2+ n -- n+2
2- n -- n-2
3+ n -- n+3
3- n -- n-3
4+ n -- n+4
4- n -- n-4
DIADIC OPERATORS
* n1 n2 -- n1*n2
*W n1 n2 -- n1*n2
Faster than * on a 68000 if you know that the operands are in the range
-32768 to +32767.
+ n1 n2 -- n1+n2
+- n1 n2 -- n3 Sets the sign of n1 to that of n2, left as n3.
- n1 n2 -- n1-n2
/ n1 n2 -- n1/n2
MAX n1 n2 -- max
MIN n1 n2 -- min
MONADIC OPERATORS
ABS n -- |n|
NEGATE n -- -n Changes the sign of n.
RANDOM n -- rand*n
Returns a random number from 0 to n-1 inclusive. n is limited to an Int
value. Larger than that means that numbers will be poorly distributed.
Uses the Toolbox call Random, but is not the same.
PREFIX OPERATORS Use for values, local variables, named input parameters.
-> n -- : word Gazinta. Stores n. Can also use to store a cfa into a vect.
++> n -- : word Adds n.
--> n -- : word Subtracts n.
NEG> -- : word Negates.
AND> n -- : word Logically ands with n.
OR> n -- : word Logically ors with n.
XOR> n -- : word Logically xors with n.
NOT> -- : word Logically nots.
MODULO
MOD n1 n2 -- rem Leaves remainder of division of n1 by n2.
/MOD n1 n2 -- rem n1/n2
divides n1 by n2 leaving the remainder under the signed quotient.
/MODW n1 n2 -- rem n1/n2
Faster version of /mod on a 68000 if you know that the operands are in
the range -32768 to +32767.
*/MOD n1 n2 n3 -- rem (n1*n2)/n3
Same as */ except also leaves the remainder of the division.
COMPARISONS
< n1 n2 -- b
<= n1 n2 -- b less than or equal
<> n1 n2 -- b not equal, perhaps we could use ≠ ?
= n1 n2 -- b
> n1 n2 -- b
>= n1 n2 -- b greater than or equal
0< n -- b less than zero
0<= n -- b less than or equal to zero
0<> n -- b not equal to zero
0= n -- b
0> n -- b greater than zero
0>= n -- b greater than or equal to zero
WITHIN? n lo hi -- n b Returns true if lo <= n <= hi.
NOT b -- -b Reverses the sense of a boolean.
TRUE -- b A constant = -1
FALSE -- b A constant = 0
LOGICAL
\ and, or, and xor perform 32-bit bit-wise logic
AND n1 n2 -- and
OR n1 n2 -- or
XOR n1 n2 -- xor
UNSIGNED
U< u1 u2 -- b
U> u1 u2 -- b
U/MOD n1 n2 -- rem n1/n2
divides n1 by n2 leaving the remainder under the unsigned quotient.
U/MODW ?
SPECIAL
*/ n1 n2 n3 -- (n1*n2)/n3
Multiplies the two signed integers n1 and n2, then divides the double
number product by the signed number n3, leaving a signed quotient.
<< n s -- n'
Shifts the bits of n to the left by s shift bits. e.g. 3 2 << will
yield 12 (0011) -> (1100).
>> n s -- n'
Shifts the bits of n to the right by s shift bits. e.g. 12 2 >>
will yield 3 (1100) -> (0011).
EXTEND w -- n Sign extends a 16 bit number to a 32 bit number, stack
alignment is unaffected.